|
|||||||||||||||||||
30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover | |||||||||||||||||||
Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
WsdlToJ2ee.java | 0% | 0% | 0% | 0% |
|
1 |
/*
|
|
2 |
* Copyright 2001-2004 The Apache Software Foundation.
|
|
3 |
*
|
|
4 |
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5 |
* you may not use this file except in compliance with the License.
|
|
6 |
* You may obtain a copy of the License at
|
|
7 |
*
|
|
8 |
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9 |
*
|
|
10 |
* Unless required by applicable law or agreed to in writing, software
|
|
11 |
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13 |
* See the License for the specific language governing permissions and
|
|
14 |
* limitations under the License.
|
|
15 |
*/
|
|
16 |
package org.apache.geronimo.ews.jaxrpcmapping;
|
|
17 |
|
|
18 |
import org.apache.axis.constants.Scope;
|
|
19 |
import org.apache.axis.utils.CLArgsParser;
|
|
20 |
import org.apache.axis.utils.CLOption;
|
|
21 |
import org.apache.axis.utils.CLOptionDescriptor;
|
|
22 |
import org.apache.axis.utils.JavaUtils;
|
|
23 |
import org.apache.axis.utils.Messages;
|
|
24 |
import org.apache.axis.wsdl.gen.Parser;
|
|
25 |
import org.apache.axis.wsdl.gen.WSDL2;
|
|
26 |
|
|
27 |
import java.util.List;
|
|
28 |
|
|
29 |
/**
|
|
30 |
* @author Ias (iasandcb@tmax.co.kr)
|
|
31 |
*/
|
|
32 |
public class WsdlToJ2ee extends WSDL2 { |
|
33 |
|
|
34 |
protected static final int MAPPING_OPT = 'm'; |
|
35 |
|
|
36 |
// Define our short one-letter option identifiers.
|
|
37 |
protected static final int SERVER_OPT = 's'; |
|
38 |
protected static final int SKELETON_DEPLOY_OPT = 'S'; |
|
39 |
protected static final int NAMESPACE_OPT = 'N'; |
|
40 |
protected static final int NAMESPACE_FILE_OPT = 'f'; |
|
41 |
protected static final int OUTPUT_OPT = 'o'; |
|
42 |
protected static final int SCOPE_OPT = 'd'; |
|
43 |
protected static final int TEST_OPT = 't'; |
|
44 |
protected static final int PACKAGE_OPT = 'p'; |
|
45 |
protected static final int ALL_OPT = 'a'; |
|
46 |
protected static final int TYPEMAPPING_OPT = 'T'; |
|
47 |
protected static final int FACTORY_CLASS_OPT = 'F'; |
|
48 |
protected static final int HELPER_CLASS_OPT = 'H'; |
|
49 |
protected static final int USERNAME_OPT = 'U'; |
|
50 |
protected static final int PASSWORD_OPT = 'P'; |
|
51 |
|
|
52 |
protected boolean bPackageOpt = false; |
|
53 |
private J2eeEmitter emitter;
|
|
54 |
|
|
55 |
/**
|
|
56 |
* Define the understood options. Each CLOptionDescriptor contains:
|
|
57 |
* - The "long" version of the option. Eg, "help" means that "--help" will
|
|
58 |
* be recognised.
|
|
59 |
* - The option flags, governing the option's argument(s).
|
|
60 |
* - The "short" version of the option. Eg, 'h' means that "-h" will be
|
|
61 |
* recognised.
|
|
62 |
* - A description of the option for the usage message
|
|
63 |
*/
|
|
64 |
protected static final CLOptionDescriptor[] options = new CLOptionDescriptor[]{ |
|
65 |
new CLOptionDescriptor("server-side", |
|
66 |
CLOptionDescriptor.ARGUMENT_DISALLOWED, |
|
67 |
SERVER_OPT, |
|
68 |
Messages.getMessage("optionSkel00")),
|
|
69 |
new CLOptionDescriptor("skeletonDeploy", |
|
70 |
CLOptionDescriptor.ARGUMENT_REQUIRED, |
|
71 |
SKELETON_DEPLOY_OPT, |
|
72 |
Messages.getMessage("optionSkeletonDeploy00")),
|
|
73 |
new CLOptionDescriptor("NStoPkg", |
|
74 |
CLOptionDescriptor.DUPLICATES_ALLOWED + CLOptionDescriptor.ARGUMENTS_REQUIRED_2, |
|
75 |
NAMESPACE_OPT, |
|
76 |
Messages.getMessage("optionNStoPkg00")),
|
|
77 |
new CLOptionDescriptor("fileNStoPkg", |
|
78 |
CLOptionDescriptor.ARGUMENT_REQUIRED, |
|
79 |
NAMESPACE_FILE_OPT, |
|
80 |
Messages.getMessage("optionFileNStoPkg00")),
|
|
81 |
new CLOptionDescriptor("package", |
|
82 |
CLOptionDescriptor.ARGUMENT_REQUIRED, |
|
83 |
PACKAGE_OPT, |
|
84 |
Messages.getMessage("optionPackage00")),
|
|
85 |
new CLOptionDescriptor("output", |
|
86 |
CLOptionDescriptor.ARGUMENT_REQUIRED, |
|
87 |
OUTPUT_OPT, |
|
88 |
Messages.getMessage("optionOutput00")),
|
|
89 |
new CLOptionDescriptor("deployScope", |
|
90 |
CLOptionDescriptor.ARGUMENT_REQUIRED, |
|
91 |
SCOPE_OPT, |
|
92 |
Messages.getMessage("optionScope00")),
|
|
93 |
new CLOptionDescriptor("testCase", |
|
94 |
CLOptionDescriptor.ARGUMENT_DISALLOWED, |
|
95 |
TEST_OPT, |
|
96 |
Messages.getMessage("optionTest00")),
|
|
97 |
new CLOptionDescriptor("all", |
|
98 |
CLOptionDescriptor.ARGUMENT_DISALLOWED, |
|
99 |
ALL_OPT, |
|
100 |
Messages.getMessage("optionAll00")),
|
|
101 |
new CLOptionDescriptor("typeMappingVersion", |
|
102 |
CLOptionDescriptor.ARGUMENT_REQUIRED, |
|
103 |
TYPEMAPPING_OPT, |
|
104 |
Messages.getMessage("optionTypeMapping00")),
|
|
105 |
new CLOptionDescriptor("factory", |
|
106 |
CLOptionDescriptor.ARGUMENT_REQUIRED, |
|
107 |
FACTORY_CLASS_OPT, |
|
108 |
Messages.getMessage("optionFactory00")),
|
|
109 |
new CLOptionDescriptor("helperGen", |
|
110 |
CLOptionDescriptor.ARGUMENT_DISALLOWED, |
|
111 |
HELPER_CLASS_OPT, |
|
112 |
Messages.getMessage("optionHelper00")),
|
|
113 |
new CLOptionDescriptor("user", |
|
114 |
CLOptionDescriptor.ARGUMENT_REQUIRED, |
|
115 |
USERNAME_OPT, |
|
116 |
Messages.getMessage("optionUsername")),
|
|
117 |
new CLOptionDescriptor("password", |
|
118 |
CLOptionDescriptor.ARGUMENT_REQUIRED, |
|
119 |
PASSWORD_OPT, |
|
120 |
Messages.getMessage("optionPassword")),
|
|
121 |
new CLOptionDescriptor("mapping-file-path", |
|
122 |
CLOptionDescriptor.ARGUMENT_REQUIRED, |
|
123 |
MAPPING_OPT, |
|
124 |
"Choose a mapping file path for J2EE JAX-RPC mapping")
|
|
125 |
}; |
|
126 |
|
|
127 | 0 |
public WsdlToJ2ee() {
|
128 | 0 |
emitter = (J2eeEmitter) parser; |
129 | 0 |
addOptions(options); |
130 |
} // ctor
|
|
131 |
|
|
132 | 0 |
protected Parser createParser() {
|
133 | 0 |
return new J2eeEmitter(); |
134 |
} // createParser
|
|
135 |
|
|
136 | 0 |
protected void parseOption(CLOption option) { |
137 | 0 |
switch (option.getId()) {
|
138 |
case FACTORY_CLASS_OPT:
|
|
139 | 0 |
emitter.setFactory(option.getArgument()); |
140 | 0 |
break;
|
141 |
case HELPER_CLASS_OPT:
|
|
142 | 0 |
emitter.setHelperWanted(true);
|
143 | 0 |
break;
|
144 |
case SKELETON_DEPLOY_OPT:
|
|
145 | 0 |
emitter.setSkeletonWanted(JavaUtils.isTrueExplicitly(option.getArgument(0))); |
146 |
// --skeletonDeploy assumes --server-side, so fall thru
|
|
147 |
|
|
148 |
case SERVER_OPT:
|
|
149 | 0 |
emitter.setServerSide(true);
|
150 | 0 |
break;
|
151 |
case NAMESPACE_OPT:
|
|
152 | 0 |
String namespace = option.getArgument(0); |
153 | 0 |
String packageName = option.getArgument(1); |
154 | 0 |
emitter.getNamespaceMap().put(namespace, packageName); |
155 | 0 |
break;
|
156 |
case NAMESPACE_FILE_OPT:
|
|
157 | 0 |
emitter.setNStoPkg(option.getArgument()); |
158 | 0 |
break;
|
159 |
case PACKAGE_OPT:
|
|
160 | 0 |
bPackageOpt = true;
|
161 | 0 |
emitter.setPackageName(option.getArgument()); |
162 | 0 |
break;
|
163 |
case OUTPUT_OPT:
|
|
164 | 0 |
emitter.setOutputDir(option.getArgument()); |
165 | 0 |
break;
|
166 |
case SCOPE_OPT:
|
|
167 | 0 |
String arg = option.getArgument(); |
168 |
|
|
169 |
// Provide 'null' default, prevents logging internal error.
|
|
170 |
// we have something different to report here.
|
|
171 | 0 |
Scope scope = Scope.getScope(arg, null);
|
172 | 0 |
if (scope != null) { |
173 | 0 |
emitter.setScope(scope); |
174 |
} else {
|
|
175 | 0 |
System.err.println(Messages.getMessage("badScope00", arg));
|
176 |
} |
|
177 | 0 |
break;
|
178 |
case TEST_OPT:
|
|
179 | 0 |
emitter.setTestCaseWanted(true);
|
180 | 0 |
break;
|
181 |
case ALL_OPT:
|
|
182 | 0 |
emitter.setAllWanted(true);
|
183 | 0 |
break;
|
184 |
case TYPEMAPPING_OPT:
|
|
185 | 0 |
String tmValue = option.getArgument(); |
186 | 0 |
if (tmValue.equals("1.1")) { |
187 | 0 |
emitter.setTypeMappingVersion("1.1");
|
188 | 0 |
} else if (tmValue.equals("1.2")) { |
189 | 0 |
emitter.setTypeMappingVersion("1.2");
|
190 |
} else {
|
|
191 | 0 |
System.out.println(Messages.getMessage("badTypeMappingOption00"));
|
192 |
} |
|
193 | 0 |
break;
|
194 |
case USERNAME_OPT:
|
|
195 | 0 |
emitter.setUsername(option.getArgument()); |
196 | 0 |
break;
|
197 |
case PASSWORD_OPT:
|
|
198 | 0 |
emitter.setPassword(option.getArgument()); |
199 | 0 |
break;
|
200 |
case MAPPING_OPT:
|
|
201 | 0 |
emitter.setMappingFilePath(option.getArgument()); |
202 | 0 |
break;
|
203 |
default:
|
|
204 | 0 |
super.parseOption(option);
|
205 |
} |
|
206 |
} // parseOption
|
|
207 |
|
|
208 |
/**
|
|
209 |
* validateOptions
|
|
210 |
* This method is invoked after the options are set to validate
|
|
211 |
* the option settings.
|
|
212 |
*/
|
|
213 | 0 |
protected void validateOptions() { |
214 | 0 |
super.validateOptions();
|
215 |
|
|
216 |
// validate argument combinations
|
|
217 | 0 |
if (emitter.isSkeletonWanted() && !emitter.isServerSide()) {
|
218 | 0 |
System.out.println(Messages.getMessage("badSkeleton00"));
|
219 | 0 |
printUsage(); |
220 |
} |
|
221 | 0 |
if (!emitter.getNamespaceMap().isEmpty() && bPackageOpt) {
|
222 | 0 |
System.out.println(Messages.getMessage("badpackage00"));
|
223 | 0 |
printUsage(); |
224 |
} |
|
225 |
} // validateOptions
|
|
226 |
|
|
227 |
/**
|
|
228 |
* run
|
|
229 |
* checkes the command-line arguments and runs the tool.
|
|
230 |
*
|
|
231 |
* @param args String[] command-line arguments.
|
|
232 |
*/
|
|
233 | 0 |
protected void run(String[] args) { |
234 |
// Parse the arguments
|
|
235 | 0 |
CLArgsParser argsParser = new CLArgsParser(args, options);
|
236 |
|
|
237 |
// Print parser errors, if any
|
|
238 | 0 |
if (null != argsParser.getErrorString()) { |
239 | 0 |
System.err.println(Messages.getMessage("error01", argsParser.getErrorString()));
|
240 | 0 |
printUsage(); |
241 |
} |
|
242 |
|
|
243 |
// Get a list of parsed options
|
|
244 | 0 |
List clOptions = argsParser.getArguments(); |
245 | 0 |
int size = clOptions.size();
|
246 |
|
|
247 |
// Parse the options and configure the emitter as appropriate.
|
|
248 | 0 |
for (int i = 0; i < size; i++) { |
249 | 0 |
parseOption((CLOption) clOptions.get(i)); |
250 |
} |
|
251 |
|
|
252 |
// validate argument combinations
|
|
253 |
//
|
|
254 | 0 |
validateOptions(); |
255 | 0 |
try {
|
256 | 0 |
parser.run(wsdlURI); |
257 |
} catch (Exception e) {
|
|
258 | 0 |
e.printStackTrace(); |
259 | 0 |
System.exit(-1); |
260 |
} |
|
261 |
} // run
|
|
262 |
|
|
263 |
/**
|
|
264 |
* Main
|
|
265 |
*/
|
|
266 | 0 |
public static void main(String args[]) { |
267 | 0 |
WsdlToJ2ee j2ee = new WsdlToJ2ee();
|
268 | 0 |
j2ee.run(args); |
269 |
} // main
|
|
270 |
} |
|
271 |
|
|